$(function() {
	//初始化表格
	var treeGrid=easyExt.treeGrid();
	//初始化工具栏
	treeGrid.url=easyExt.url+'/sys_privilege/findAll?type=F';
	treeGrid.toolbar="#toolbar";

	$('#tg').treegrid(treeGrid).treegrid('clientPaging');
	//删除实现
	$("#del").click(function(){
		var selRows=$('#tg').treegrid('getSelections');
		easyExt.del('id',selRows,'/sys_privilege/deleteBatch',function(){//删除成功后执行的动作，一般用于刷新datagrid
			$('#tg').treegrid('clearSelections');
			$('#tg').treegrid('reload'); 
		});
	});
	//添加实现
	$("#add").click(function(){
		easyExt.add('/sys_privilege/saveOne',function(){
			$('#addDialog').dialog('close');
			$('#tg').treegrid('reload'); 
			$('#parent').combotree('reload',easyExt.url+'/sys_privilege/tree');
		});
	});
	//修改实现
	$("#edit").click(function(){
		var selRows=$('#tg').treegrid('getSelections');
		easyExt.edit(selRows,'/sys_privilege/updateOne',function(){
			$('#addDialog').dialog('close');
			$('#tg').treegrid('clearSelections');
			$('#tg').treegrid('reload'); 
		});
	});
	//上级菜单
	$('#parent').combotree({
		method: 'GET',
	    url: easyExt.url+'/sys_privilege/getTopMenu',
	    animate:true,
	    onSelect:function(node){
	    	$('#parentId').attr("value",node.id);
	    }
	});
});

